import { knowaddQuestion,getAlikeQuestionList,getStandardQuestion,editQustion,deleteQuestion,topQuesion} from '@/services/knowledgemanagement';

export default {
  namespace: 'question',
  state: {
    total: null,
    items: [],
    loading: false
  },
  effects: {
    *addQus({payload,callback}, { call, put }) {
      const response = yield call(knowaddQuestion,payload);
      if (callback && typeof callback === 'function') {
        callback(response);
      }
      yield put({
        type: 'save',
        payload: response,
      });
    },
    *getQuestionsByQaId({payload,callback}, { call, put }) {
      const response = yield call(getAlikeQuestionList,payload);
      if (callback && typeof callback === 'function') {
        callback(response);
      }
      yield put({
        type: 'save',
        payload: response,
      });
    },
    *getStandardQuestionByQaId({payload,callback}, { call, put }) {
      const response = yield call(getStandardQuestion,payload);
      if (callback && typeof callback === 'function') {
        callback(response);
      }
      yield put({
        type: 'save',
        payload: response,
      });
    },
    *editQus({payload,callback}, { call, put }) {
      const response = yield call(editQustion,payload);
      if (callback && typeof callback === 'function') {
        callback(response);
      }
      yield put({
        type: 'save',
        payload: response,
      });
    },
    *delQus({payload,callback}, { call, put }) {
      const response = yield call(deleteQuestion,payload);
      if (callback && typeof callback === 'function') {
        callback(response);
      }
      yield put({
        type: 'save',
        payload: response,
      });
    },
    *topQus({payload,callback}, { call, put }) {
      const response = yield call(topQuesion,payload);
      if (callback && typeof callback === 'function') {
        callback(response);
      }
      yield put({
        type: 'save',
        payload: response,
      });
    },
  },

  reducers: {
    save(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    }
  }
};
